#ifndef _init_hpp_
#define _init_hpp_

/** \file init.hpp
 *  \author Adrian Schweizer
 *  \created  $Mi 29 Aug 03:11:38 pm CEST 2007 schwadri@SchwadriComp.local$
 *  \modified $Mi 29 Aug 03:31:11 pm CEST 2007 schwadri@SchwadriComp.local$
 */

namespace core {

    namespace math {

        template<class Vector, int I, int N>
            struct set_entry;

        template<class Vector, int N>
            struct set_entry<Vector,1,N>
            {
                set_entry(Vector& a)
                :   v(a),
                    w(true)
                { }

                template<class S>
                    set_entry<Vector,2,N>  operator,(const S& value)
                    {
                        *(v.begin()+1) = value;
                        w = false;
                        return set_entry<Vector,2,N>(v);
                    }

                ~set_entry();

                Vector& v;
                mutable bool w;
            };

        template<class Vector, int I, int N>
            struct set_entry
            {
                set_entry(Vector& a)
                :   v(a)
                { }

                template<class S>
                    set_entry<Vector,I+1,N>  operator,(const S& value)
                    {
                        *(v.begin()+I) = value;
                        return set_entry<Vector,I+1,N>(v);
                    }
               Vector& v;
            };

        template<class T>
            struct exceeded_vector_dimension;

            struct postpone
            {
                template<class T>
                    struct apply
                    {
                        typedef typename T::type    type;
                    };
            };

        template<class Vector, int N>
            struct set_entry<Vector,N,N>
            {
                set_entry(Vector& a)
                :   v(a)
                { }

                template<class S>
                    Vector&  operator,(const S& value)
                    {
                        //instancate something that leads to an compile time error
                        typename postpone::template apply<exceeded_vector_dimension<S> >::type exceed;
                        return v;
                    }

                operator const Vector&()
                {
                    return v;
                }

               Vector& v;
            };

        template<class Vector, int N>
            set_entry<Vector,1,N>::~set_entry()
            {
                if(w)
                    v.set(*(v.begin()));
            }

    } // namespace math

} // namespace core

#endif // _init_hpp_
